package com.lovi.common;

import com.lovi.thread_.ManageServerConnectClientThread;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
@Data
public class UsersMap {
    //创建有效的用户集合
    public static ConcurrentHashMap<String,String> usersMap = new ConcurrentHashMap<>();
    static {
        usersMap.put("100","123456");
        usersMap.put("200","123456");
        usersMap.put("蔡依林","123456");
        usersMap.put("陈乔恩","123456");
        usersMap.put("张韶涵","123456");
    }
    /**
     * 判断是否为离线用户
     */
    public static boolean isOfflineUser(String userId){
        List<String> onlineUsers2 = ManageServerConnectClientThread.getOnlineUsers2();
        //用户包含并且在线用户不包含则为离线用户
        if(usersMap.containsKey(userId)&&!onlineUsers2.contains(userId)){
            return true;
        }
        return false;
    }
    /**
     * 得到离线用户列表
     */
    public static List<String> getOfflineUsers(){
        List<String> list = new ArrayList<>();
        ConcurrentHashMap.KeySetView<String, String> strings = usersMap.keySet();
        for (String userId : strings) {
            if(isOfflineUser(userId)){
                list.add(userId);
            }
        }
        return list;
    }
}
